package com.javasm.gm;

import com.javasm.commons.base.BaseController;
import com.javasm.commons.entity.AxiosResult;
import com.javasm.commons.entity.TableDatas;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/gift")
public class GiftController extends BaseController {
    @Autowired
    private GiftService giftService;

    @GetMapping
    public TableDatas getAll(Gift g) {
        startPage();
        List<Gift> l = giftService.listGift(g);
        return toTableDatas(l);
    }

    @PostMapping
    public AxiosResult addGift(@RequestBody Gift sysGift) {
        boolean save = giftService.save(sysGift);
        if(save)return suc();
        return AxiosResult.error();
    }

    @PutMapping
    public AxiosResult updateById(@RequestBody Gift sysGift) {
        boolean result = giftService.updateById(sysGift);
        if (result) {
            return suc();
        }
        return AxiosResult.error();
    }

    @DeleteMapping
    public AxiosResult deleteById(@RequestParam Integer id) {
        boolean b = giftService.removeById(id);
        return isok(b);
    }
}
